home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / lexing.mli < prev    next >
Encoding:
Text File  |  1994-07-07  |  3.2 KB  |  76 lines  |  [TEXT/MPS ]

  1. (* The run-time library for lexers generated by camllex *)
  2.  
  3. #open "io";;
  4. #open "obj";;
  5.  
  6. (*** Lexer buffers *)
  7.  
  8. type lexbuf =
  9.   { refill_buff : lexbuf -> unit;
  10.     lex_buffer : string;
  11.     mutable lex_abs_pos : int;
  12.     mutable lex_start_pos : int;
  13.     mutable lex_curr_pos : int;
  14.     mutable lex_last_pos : int;
  15.     mutable lex_last_action : lexbuf -> obj }
  16. ;;
  17.         (* The type of lexer buffers. A lexer buffer is the argument passed
  18.            to the scanning functions defined by the generated scanners.
  19.            The lexer buffer holds the current state of the scanner, plus
  20.            a function to refill the buffer from the input. *)
  21.  
  22. value create_lexer_channel : in_channel -> lexbuf
  23.         (* Create a lexer buffer on the given input channel.
  24.            [create_lexer_channel inchan] returns a lexer buffer which reads
  25.            from the input channel [inchan], at the current reading position. *)
  26.   and create_lexer_string : string -> lexbuf
  27.         (* Create a lexer buffer which reads from
  28.            the given string. Reading starts from the first character in
  29.            the string. An end-of-input condition is generated when the
  30.            end of the string is reached. *)
  31.   and create_lexer : (string -> int -> int) -> lexbuf
  32.         (* Create a lexer buffer with the given function as its reading method.
  33.            When the scanner needs more characters, it will call the given
  34.            function, giving it a character string [s] and a character
  35.            count [n]. The function should put [n] characters or less in [s],
  36.            starting at character number 0, and return the number of characters
  37.            provided. A return value of 0 means end of input. *)
  38. ;;
  39.  
  40. (*** Functions for lexer semantic actions *)
  41.  
  42.         (* The following functions can be called from the semantic actions
  43.            of lexer definitions (the ML code enclosed in braces that
  44.            computes the value returned by lexing functions). They give
  45.            access to the character string matched by the regular expression
  46.            associated with the semantic action. These functions must be
  47.            applied to the argument [lexbuf], which, in the code generated by
  48.            camllex, is bound to the lexer buffer passed to the parsing
  49.            function. *)
  50.  
  51. value get_lexeme : lexbuf -> string
  52.         (* [get_lexeme lexbuf] returns the string matched by
  53.            the regular expression. *)
  54.   and get_lexeme_char : lexbuf -> int -> char
  55.         (* [get_lexeme_char lexbuf i] returns character number [i] in
  56.            the matched string. *)
  57.   and get_lexeme_start : lexbuf -> int
  58.         (* [get_lexeme_start lexbuf] returns the position in the input stream
  59.            of the first character of the matched string. The first character
  60.            of the stream has position 0. *)
  61.   and get_lexeme_end : lexbuf -> int
  62.         (* [get_lexeme_end lexbuf] returns the position in the input stream
  63.            of the character following the last character of the matched
  64.            string. The first character of the stream has position 0. *)
  65. ;;
  66.  
  67. (*--*)
  68.  
  69. (* The following definitions are used by the generated scanners only.
  70.    They are not intended to be used by user programs. *)
  71.  
  72. value dummy_action : lexbuf -> obj
  73.   and get_next_char : lexbuf -> char = 1 "get_next_char"
  74.   and backtrack : lexbuf -> 'a
  75. ;;
  76.